<template>
  <div>
    <h1>新建分类</h1>
    <el-form ref="form" :model="form" label-width="80px">

    <el-form-item label="上级分类">
    <el-select v-model="form.parent">
      <el-option v-for="item in parents" :key="item._id" :label="item.name" :value="item._id"></el-option>
    </el-select>
    </el-form-item>
      <el-form-item label="活动名称">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-button @click="save()">创建</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form:{
        name:''
      },
      // 父级的选项
      parents:[],
    };
  },
  created() {
    this.parentOptions()
  },
  methods: {
   async save() {
      const res = await this.$http.post('/rest/categories',this.form)
      console.log(res)
    },

    // 获取父级选项
    async parentOptions(){
      const res = await this.$http.get('/rest/categories')
      this.parents=res.data
      console.log(res)
    }
  },
};
</script>